<?php
namespace Common\Mysql;
class PageMysql extends CommonMysql {
    public function addPage($data) {
        $title = v($data,'title');
        verify($title,'notEmpty','单页标题不能为空');

        $html = v($data,'html');
        verify($html,'notEmpty','单页内容');

        $status = v($data,'status',1,true);
        verify($status,'isStatus','非法状态');

        $sid = v($data,'sid',0,true);
        verify($sid,'notEmpty','网站ID不能为空');

        if($this->where("`title`='{$title}'")->count()) {
            E('单页已经存在');
        }

        $id = $this->addRecord(array(
            'title'     =>  $title,
            'html'      =>  $html,
            'sid'       =>  $sid,
            'createtime'=>  NOW_TIME,
            'updatetime'=>  NOW_TIME,
            'status'    =>  $status,
        ),false,'单页添加成功');

        return $id;
    }
    public function updatePage($data) {
        $id = v($data,'id');
        verify($id,'notEmpty','单页ID不能为空');
        verify($id,'isID','非法单页ID');

        $title = v($data,'title');
        verify($title,'notEmpty','单页标题不能为空');

        $html = v($data,'html');
        verify($html,'notEmpty','单页内容');

        $sid = v($data,'sid',0,true);
        verify($sid,'notEmpty','网站ID不能为空');

        $status = v($data,'status',1,true);
        verify($status,'isStatus','非法状态');

        if($this->where("`title`='{$title}' AND `id`<>{$id}")->count()) {
            E('单页已经存在');
        }

        $pageInfo = M('Page')->find($id);;
        verify($pageInfo,'notEmpty','网站不存在');
    
        $this->updateRecord(array(
            'id'        =>  $id,
            'title'     =>  $title,
            'html'      =>  $html,
            'sid'       =>  $sid,
            'updatetime'=>  NOW_TIME,
            'status'    =>  $status,
        ),false,'单页修改失败');

        return $id;
    }
}
?>
